package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.IUserDao;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.util.GetSqlSession;

import java.util.List;
import java.util.Map;

public class UserDaoImpl implements IUserDao {
    @Override
    public int addUser(UserModel userModel) {
        int count = GetSqlSession.getSqlSession().insert("com.cn.wanxi.dao.IUserDao.addUser",userModel);
        return count;
    }

    @Override
    public int updateUser(UserModel userModel) {
        return GetSqlSession.getSqlSession().update("com.cn.wanxi.dao.IUserDao.updateUser",userModel);
    }

    @Override
    public int deleteUser(int id) {
        return GetSqlSession.getSqlSession().update("com.cn.wanxi.dao.IUserDao.deleteUser",String.valueOf(id));
    }

    @Override
    public UserModel getUser(int id) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IUserDao.getUser",String.valueOf(id));
    }

    @Override
    public List<UserModel> getUserList() {
        return GetSqlSession.getSqlSession().selectList("com.cn.wanxi.dao.IUserDao.getUserList");
    }

    @Override
    public List<UserModel> getUsers(Map<String, Object> params) {
        return GetSqlSession.getSqlSession().selectList("com.cn.wanxi.dao.IUserDao.getUsers",params);
    }

    @Override
    public UserModel getUserByUsername(String username) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IUserDao.getUserByUsername",username);
    }

    @Override
    public UserModel login(UserModel userModel) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IUserDao.login",userModel);
    }

    @Override
    public long getUserCount(Map<String, Object> map) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IUserDao.getUserCount",map);
    }

}
